package com.k.base.jdk.proxy.demo2;

import com.k.base.jdk.proxy.demo2.frm.ProxyAction;

import java.lang.reflect.Method;

public class NoticeProxyAction implements ProxyAction {
    @Override
    public void before(Object proxy, Method method, Object[] args) {
        /**
         * notice after
         * notice afterReturn:BMW
         * brand:BMW
         */
//        System.out.println(1/0);
//        Car carProxy = (Car) proxy;
//        carProxy.run();
        System.out.println("notice before");

    }

    @Override
    public void after(Object proxy, Method method, Object[] args,Object result) {
        /**
         * notice before
         * notice afterReturn:BMW
         * brand:BMW
         */
//        System.out.println(1/0);
        System.out.println("notice after:"+result);
    }

    // 代理方法异常
    /**
     * notice before
     * notice exception
     * notice afterReturn:null
     */

    @Override
    public void exception(Object proxy, Method method, Object[] args) {
        /**
         * notice before
         * notice after
         * notice afterReturn:BMW
         * brand:BMW
         */
//        System.out.println(1/0);
        System.out.println("notice exception");

    }

    @Override
    public void afterReturn(Object proxy, Method method, Object[] args,Object result) {
        /**
         * notice before
         * notice after
         * brand:BMW
         */
//        System.out.println(1/0);
        System.out.println("notice afterReturn:"+result);
    }
}
